// index.js
// 获取应用实例
const app = getApp()
Page({
  data: {
    id: null,
    isLogin: null,
    fullAccess: null,
    isSearchOn: false,
    buttonsAdmin:[
      {
        title: '系统用户管理',
        path: '../index/systemUser/systemUser' //这里填你做好的页面的Path
      },
      {
        title: '用户注册管理',
        path: '../index/addUser/addUser'
      },
      {
        title: '留言管理',
        path: '../index/doctorOrder/doctorOrder'
      },
      {
        title: '医生管理',
        path: '../doctor/doctor'
      },
      {
        title: '科室管理',
        path: '../departments/departments'
      },
      {
        title: '预约挂号管理',
        path: '../appointmentDoc/appointmentDoc'
      },
      {
        title: '系统管理',
        path: '../system/system'
      }
    ],
    list: [
      {
        title: '处方信息',
        path: ''
      },
      {
        title: '病历',
        path: ''
      },
      {
        title: '修改密码',
        path: '../resetPassword/resetPassword'
      }
    ]
  },
  // 事件处理函数
  toPage(event){
    let path = event.currentTarget.dataset.path;
    wx.navigateTo({
      url: path,
    })
  },
  toLogin() {
    wx.navigateTo({
      url: '../login/login'
    })
  },
  onLoad() {
  },
  onShow(){
    if (typeof this.getTabBar === 'function' &&
        this.getTabBar()) {
        this.getTabBar().setData({
          selected: 0
        })
      }
      let id = app.globalData.userId;
      let isLogin = app.globalData.isLogin;
      this.setData({
        id: id,
        isLogin: isLogin
      });
      if(this.data.id == 1){
        this.setData({fullAccess: app.globalData.adminFullAccess});
        this.getTabBar().switchToAdmin();
      }
  },
  searchOn(){
    let val = !this.data.isSearchOn;
    this.setData({isSearchOn: val});
  },
  toAppointment(){
    if(!this.data.isLogin){
      wx.showToast({
        title: '请先登录',
        duration: 1000,
        icon: 'none'
      });
      return;
    }
    wx.navigateTo({
      url: '../appointment/department/department',
    })
  },
  toChat(){
    if(!this.data.isLogin){
      wx.showToast({
        title: '请先登录',
        duration: 1000,
        icon: 'none'
      });
      return;
    }
    wx.navigateTo({
      url: '../chatRoom/selectDoctor/selectDoctor',
    })
  },
  toHistory(){
    if(!this.data.isLogin){
      wx.showToast({
        title: '请先登录',
        duration: 1000,
        icon: 'none'
      });
      return;
    }
    wx.navigateTo({
      url: '../history/history',
    })
  },
  toSearch(){
    if(!this.data.isLogin){
      wx.showToast({
        title: '请先登录',
        duration: 1000,
        icon: 'none'
      });
      return;
    }
    wx.navigateTo({
      url: '../paper/searchPaper',
    })
  },
  toCare(){
    if(!this.data.isLogin){
      wx.showToast({
        title: '请先登录',
        duration: 1000,
        icon: 'none'
      });
      return;
    }
    wx.navigateTo({
      url: '../advice/advice',
    })
  },
  toPath(event){
    let path = event.currentTarget.dataset.path;
    wx.navigateTo({
      url: path
    });
  },
  logOut(){
    //登出
    let _this = this;
    wx.showModal({
      title: '提示',
      content: '确认退出登录吗？',
      success(res){
        if(res.confirm){
          getApp().globalData.isLogin = false;
          getApp().globalData.userId = null;
          _this.setData({isLogin: false,id: null});
          _this.getTabBar().switchToUnit();
          wx.switchTab({
            url: '../index/index',
          });
        }
      }
    })
  },
  toAppointmentManage(){
    wx.navigateTo({
      url: '../appointment/selectPatient/selectPatient',
    })
  },
  toConsult(){
    wx.navigateTo({
      url: '../chatRoom/selectPatient/selectPatient',
    })
  },
  toAdvice(){
    wx.navigateTo({
      url: '../advice/selectPatient/selectPatient',
    })
  }
})
